<?php

namespace App\Admin\Controllers;

use App\Admin\Renderable\UserTable;
use App\Admin\Repositories\SinInLog;
use App\Models\User;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class SinInLogController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new SinInLog(['user']), function (Grid $grid) {
            $grid->model()->orderBy('id', 'desc');
            $grid->column('id')->sortable();
            $grid->column('user.nickname',"用户名");
            $grid->column('created_at');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->equal("user_id")->selectTable(UserTable::make())
                    ->title("用户选择")
                    ->model(User::class,'id',"nickname");
            });

            $grid->disableEditButton();
            $grid->disableCreateButton();
            $grid->disableDeleteButton();
            $grid->disableViewButton();
            // 禁用批量删除按钮
            $grid->disableBatchDelete();

        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
//    protected function detail($id)
//    {
//        return Show::make($id, new SinInLog(), function (Show $show) {
//            $show->field('id');
//            $show->field('user_id');
//            $show->field('created_at');
//            $show->field('updated_at');
//        });
//    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
//    protected function form()
//    {
//        return Form::make(new SinInLog(), function (Form $form) {
//            $form->display('id');
//            $form->text('user_id');
//
//            $form->display('created_at');
//            $form->display('updated_at');
//        });
//    }
}
